# 设定模块名称
set(TARGET sys_config)

# openssl加密算法库
# 设置OPENSSL的根目录
if (NOT DEFINED OPENSSL_ROOT_DIR)
    set(OPENSSL_ROOT_DIR /usr/local/lib64)
endif ()
# 从根目录寻找cmake配置文件
find_package(OpenSSL 3.5.1 CONFIG REQUIRED)
# 使用OPEN_SSL的静态库
if (OpenSSL_FOUND)
    set(OPENSSL_USE_STATIC_LIBS TRUE)
endif ()

# 在src目录下搜集源码文件
aux_source_directory(src SOURCE_FILES)

# 将模块打包成静态库
add_library(${TARGET}
    STATIC
        ${SOURCE_FILES}
)

# 给模块起个别名，便与其他模块引用(原名的目标依然存在)
add_library(${PROJECT_NAME}::${TARGET} ALIAS ${TARGET})

# 根据构建类型，定义预编译宏
if (CMAKE_BUILD_TYPE STREQUAL Debug)
    # 定义在开发环境下，config.ini文件的路径
    set(CONFIG_YAML_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/conf/config.yaml")
elseif (CMAKE_BUILD_TYPE STREQUAL Release)
    # 定义在生产环境下，config.ini文件的路径
    set(CONFIG_YAML_FILE_PATH "/usr/local/etc/${PROJECT_NAME}/config.yaml")
endif ()

message("config.ini文件的路径：CONFIG_YAML_FILE_PATH => ${CONFIG_YAML_FILE_PATH}")

# 将配置文件拷贝到/etc/network_prober目录下
install(
    FILES "${CMAKE_CURRENT_SOURCE_DIR}/conf/config.yaml"
    DESTINATION "/usr/local/etc/${PROJECT_NAME}"
#    PERMISSIONS GROUP_READ
    COMPONENT etc
)

target_include_directories(${TARGET}
    PUBLIC
        include
)

# 预定义宏：配置文件路径
target_compile_definitions(${TARGET}
    PRIVATE
        CONFIG_YAML_FILE_PATH="${CONFIG_YAML_FILE_PATH}"
)

# 为模块添加依赖
target_link_libraries(${TARGET}
    PRIVATE
        ${PROJECT_NAME}::logger
        yaml-cpp::yaml-cpp   # yaml文件操作库
        Boost::format   # 格式化
        cpuid::cpuid    # cpu信息获取库
        OpenSSL::SSL    # ssl/tls协议
        OpenSSL::Crypto # 加密算法
#        PcapPlusPlus::Pcap++ # 网口信息 静态库
)

# 给模块增加预编译头文件
target_precompile_headers(${TARGET}
    PRIVATE
        ${PROJECT_INCLUDE_DIR}/pre_compiled.h
)